//
//  ScrollView.m
//  dada
//
//  Created by 杨运涛 on 16/3/16.
//  Copyright © 2016年 aq1. All rights reserved.
//
#define DEFAULT_LEFT_DIS 20
#define DEFAULT_TOP 35
#define DEFAULT_RECT CGRectMake(DEFAULT_LEFT_DIS, DEFAULT_TOP, [UIScreen mainScreen].bounds.size.width - DEFAULT_LEFT_DIS * 2, [UIScreen mainScreen].bounds.size.height - 220)

#define DEFAULT_CENTER CGPointMake([UIScreen mainScreen].bounds.size.width / 2, [UIScreen mainScreen].bounds.size.width / 2)


#import "ScrollView.h"

@interface ScrollView ()
{
    NSMutableArray *pArraySubViews;
    
    UIButton *btnDisLike;
    UIButton *btnLike;
    UIButton *btnRefresh;
}
@property (weak, nonatomic) HSCButton *pbtn1;
@property (weak, nonatomic) HSCButton *pbtn2;
@property (weak, nonatomic) HSCButton *pbtn3;
@property (weak, nonatomic) HSCButton *pbtn4;

@end

@implementation ScrollView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        if (!btnDisLike)
        {
            btnDisLike = [[UIButton alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width / 2 - 100, DEFAULT_TOP + [UIScreen mainScreen].bounds.size.height - 220 + 28, 80, 80)];
            [btnDisLike setImage:[UIImage imageNamed:@"notLike"] forState:UIControlStateNormal];
            [btnDisLike addTarget:self action:@selector(btnDislikeAction:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:btnDisLike];
            
            btnLike = [[UIButton alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width / 2 + 20, btnDisLike.frame.origin.y, 80, 80)];
            [btnLike setImage:[UIImage imageNamed:@"love"] forState:UIControlStateNormal];
            [btnLike addTarget:self action:@selector(btnLikeAction:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:btnLike];
            
//            btnRefresh = [[UIButton alloc] initWithFrame:CGRectMake(btnDisLike.frame.origin.x - 60 - 30, btnDisLike.frame.origin.y + 20, 60, 60)];
//            [btnRefresh setImage:[UIImage imageNamed:@"refresh"] forState:UIControlStateNormal];
//            [btnRefresh addTarget:self action:@selector(btnReloadListAction:) forControlEvents:UIControlEventTouchUpInside];
//            [self addSubview:btnRefresh];
        }
        
        pArraySubViews = [NSMutableArray array];
    }
    return self;
}

- (void)setPArrayData:(NSMutableArray *)pArrayData {
    _pArrayData = pArrayData;
    if (!_pbtn1) {
        [self reloadShowView];
    }
}

- (void)btnLikeAction:(UIButton *)sender {
    [self selSelectMoveWay:em_right];
}

- (void)btnDislikeAction:(UIButton *)sender {
    [self selSelectMoveWay:em_left];
}

- (void)btnReloadListAction:(id)sender {
    [self selRloadUserList];
    if ([self.pDelegate respondsToSelector:@selector(selDidSelectRefresh)]) {
        [self.pDelegate selDidSelectRefresh];
    }
}

- (void)reloadShowView
{
    if (_pArrayData.count >= 4) {
        XYuser *user = [_pArrayData objectAtIndex:3];
        HSCButton *view1 =  [[HSCButton alloc] initWithFrame:CGRectMake(DEFAULT_RECT.origin.x + 10, DEFAULT_RECT.origin.y + 40, [UIScreen mainScreen].bounds.size.width - (DEFAULT_LEFT_DIS + 10) * 2, [UIScreen mainScreen].bounds.size.height - 220 - 20)];
        [view1 setPUser:user];
        [view1 setBackgroundColor:[UIColor blueColor]];
        [self addSubview:view1];
        [view1 setUserInteractionEnabled:NO];
        _pbtn1 = view1;
        [view1 setAccessibilityIdentifier:user.uid];
        [view1.layer setBorderWidth:0.5f];
        [view1.layer setBorderColor:[UIColor grayColor].CGColor];
        [view1.layer setCornerRadius:5.0f];
        [view1.layer setMasksToBounds:YES];
        [pArraySubViews addObject:view1];
        
        UIPanGestureRecognizer *recognizer1 = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(dragContentView:)];
        [_pbtn1 addGestureRecognizer:recognizer1];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gesTapUserAction:)];
        [view1 addGestureRecognizer:tap];
    }
    
    if (_pArrayData.count >= 3) {
        XYuser *user = [_pArrayData objectAtIndex:2];
        HSCButton *view2 = [[HSCButton alloc] initWithFrame:CGRectMake(DEFAULT_RECT.origin.x + 10, DEFAULT_RECT.origin.y + 40, [UIScreen mainScreen].bounds.size.width - (DEFAULT_LEFT_DIS + 10) * 2, [UIScreen mainScreen].bounds.size.height - 220 - 20)];
        [view2 setPUser:user];
        [view2 setBackgroundColor:[UIColor greenColor]];
        [self addSubview:view2];
        [view2 setUserInteractionEnabled:NO];
        [view2.layer setBorderWidth:0.5f];
        [view2.layer setBorderColor:[UIColor grayColor].CGColor];
        [view2.layer setCornerRadius:5.0f];
        [view2.layer setMasksToBounds:YES];
        [view2 setAccessibilityIdentifier:user.uid];
        _pbtn2 = view2;
        [pArraySubViews addObject:view2];
        
        UIPanGestureRecognizer *recognizer2 = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(dragContentView:)];
        [_pbtn2 addGestureRecognizer:recognizer2];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gesTapUserAction:)];
        [view2 addGestureRecognizer:tap];
    }
    
    if (_pArrayData.count >= 2) {
        XYuser *user = [_pArrayData objectAtIndex:1];

        HSCButton *view3 = [[HSCButton alloc] initWithFrame:CGRectMake(DEFAULT_RECT.origin.x + 5, DEFAULT_RECT.origin.y + 20, [UIScreen mainScreen].bounds.size.width - (DEFAULT_LEFT_DIS + 5) * 2, [UIScreen mainScreen].bounds.size.height - 220 - 10)];
        [view3 setPUser:user];
        [view3 setBackgroundColor:[UIColor grayColor]];
        [view3 setUserInteractionEnabled:NO];
        [view3.layer setBorderWidth:0.5f];
        [view3.layer setBorderColor:[UIColor grayColor].CGColor];
        [view3.layer setCornerRadius:5.0f];
        [view3.layer setMasksToBounds:YES];
        [view3 setAccessibilityIdentifier:user.uid];
        [self addSubview:view3];
        _pbtn3 = view3;
        [pArraySubViews addObject:view3];
        
        UIPanGestureRecognizer *recognizer3 = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(dragContentView:)];
        [_pbtn3 addGestureRecognizer:recognizer3];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gesTapUserAction:)];
        [view3 addGestureRecognizer:tap];

    }
    
    if (_pArrayData.count >= 1) {
        XYuser *user = [_pArrayData objectAtIndex:0];
        HSCButton *view = [[HSCButton alloc] initWithFrame:DEFAULT_RECT];
        [view setPUser:user];
        [view setBackgroundColor:[UIColor grayColor]];
        [self addSubview:view];
        [view.layer setBorderWidth:0.5f];
        [view.layer setBorderColor:[UIColor grayColor].CGColor];
        [view.layer setCornerRadius:5.0f];
        [view.layer setMasksToBounds:YES];
        [view setAccessibilityIdentifier:user.uid];

        _pbtn4 = view;
        [pArraySubViews addObject:view];
        
        UIPanGestureRecognizer *recognizer4 = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(dragContentView:)];
        [_pbtn4 addGestureRecognizer:recognizer4];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gesTapUserAction:)];
        [view addGestureRecognizer:tap];

    }
    
    if ([self.pDelegate respondsToSelector:@selector(selShowUserInfo:)]) {
        if (_pArrayData.count > 0) {
            [self.pDelegate selShowUserInfo:[_pArrayData firstObject]];
        }
    }
}

- (void)selAddBottomItem
{
    if (_pArrayData.count >= 4) {
        XYuser *user = [_pArrayData objectAtIndex:3];
        HSCButton *view1 = [[HSCButton alloc] initWithFrame:CGRectMake(DEFAULT_RECT.origin.x + 10, DEFAULT_RECT.origin.y + 40, [UIScreen mainScreen].bounds.size.width - (DEFAULT_LEFT_DIS + 10) * 2, [UIScreen mainScreen].bounds.size.height - 220 - 20)];
        [view1 setPUser:user];
        [view1 setBackgroundColor:[UIColor grayColor]];
        _pbtn1 = view1;
        [self insertSubview:view1 belowSubview:_pbtn2];
        [view1 setUserInteractionEnabled:NO];
        [view1 setUserInteractionEnabled:NO];
        [view1.layer setBorderWidth:0.5f];
        [view1.layer setBorderColor:[UIColor grayColor].CGColor];
        [view1.layer setCornerRadius:5.0f];
        [view1.layer setMasksToBounds:YES];
        [view1 setAccessibilityIdentifier:user.uid];
        [pArraySubViews addObject:view1];
        
        UIPanGestureRecognizer *recognizer1 = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(dragContentView:)];
        [_pbtn1 addGestureRecognizer:recognizer1];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gesTapUserAction:)];
        [view1 addGestureRecognizer:tap];
    }
    
    if ([self.pDelegate respondsToSelector:@selector(selWillReloadData)]) {
        if (_pArrayData.count == 4) {
            [self.pDelegate selWillReloadData];
        }
    }
}

- (void)dragContentView:(UIPanGestureRecognizer *)pan
{
    __block HSCButton *panView = (HSCButton *)pan.view;
    
    CGPoint translation = [pan translationInView:self];

    CGFloat x = [panView center].x + translation.x;
    CGFloat y = [panView center].y + translation.y;
    
    [pan.view setCenter:CGPointMake(x, y)];
    [pan setTranslation:CGPointZero inView:panView];
    
    if (translation.x > 0) {
        panView.pEm_Movie_Way = em_right;
    } else if (translation.x < 0) {
        panView.pEm_Movie_Way = em_left;
    } else {
        panView.pEm_Movie_Way = em_no;
    }
    
    if (pan.state == UIGestureRecognizerStateEnded) {
        if (panView.center.x - DEFAULT_CENTER.x > [UIScreen mainScreen].bounds.size.width / 5) {
            [UIView animateWithDuration:0.5 animations:^{
                panView.pEm_Movie_Way = em_right;
                [pan.view setCenter:[self selRight:panView.center]];
                [_pbtn1 setFrame:CGRectMake(DEFAULT_RECT.origin.x + 10, DEFAULT_RECT.origin.y + 40, [UIScreen mainScreen].bounds.size.width - (DEFAULT_LEFT_DIS + 10) * 2, [UIScreen mainScreen].bounds.size.height - 220 - 20)];
                [_pbtn2 setFrame:CGRectMake(DEFAULT_RECT.origin.x + 5, DEFAULT_RECT.origin.y + 20, [UIScreen mainScreen].bounds.size.width - (DEFAULT_LEFT_DIS + 5) * 2, [UIScreen mainScreen].bounds.size.height - 220 - 10)];
                [_pbtn3 setFrame:DEFAULT_RECT];
                
                _pbtn4 = _pbtn3;
                _pbtn3 = _pbtn2;
                _pbtn2 = _pbtn1;
                [_pbtn4 setUserInteractionEnabled:YES];
                _pbtn1 = nil;
                [self requestUserLike:[_pArrayData firstObject]];
                if (_pArrayData.count >0) {
                    [_pArrayData removeObjectAtIndex:0];
                    NSLog(@"csxdfasdasdsad");
                }
                
                if ([self.pDelegate respondsToSelector:@selector(selShowUserInfo:)]) {
                    if (_pArrayData.count > 0) {
                        [self.pDelegate selShowUserInfo:[_pArrayData firstObject]];
                    }
                }

                [self selAddBottomItem];
            } completion:^(BOOL finished) {
                panView.pEm_Movie_Way = em_no;
                [panView removeGestureRecognizer:pan];
                [panView removeFromSuperview];
                panView = nil;
            }];
        } else if(DEFAULT_CENTER.x - panView.center.x > [UIScreen mainScreen].bounds.size.width / 5) {
            [UIView animateWithDuration:0.5 animations:^{
                panView.pEm_Movie_Way = em_left;
                [pan.view setCenter:[self selLeft:panView.center]];
                [_pbtn1 setFrame:CGRectMake(DEFAULT_RECT.origin.x + 10, DEFAULT_RECT.origin.y + 40, [UIScreen mainScreen].bounds.size.width - (DEFAULT_LEFT_DIS + 10) * 2, [UIScreen mainScreen].bounds.size.height - 220 - 20)];
                [_pbtn2 setFrame:CGRectMake(DEFAULT_RECT.origin.x + 5, DEFAULT_RECT.origin.y + 20, [UIScreen mainScreen].bounds.size.width - (DEFAULT_LEFT_DIS + 5) * 2, [UIScreen mainScreen].bounds.size.height - 220 - 10)];
                [_pbtn3 setFrame:DEFAULT_RECT];
                
                _pbtn4 = _pbtn3;
                _pbtn3 = _pbtn2;
                _pbtn2 = _pbtn1;
                [_pbtn4 setUserInteractionEnabled:YES];
                _pbtn1 = nil;
                if (_pArrayData.count >0) {
                          [_pArrayData removeObjectAtIndex:0];
                }
          
                if ([self.pDelegate respondsToSelector:@selector(selShowUserInfo:)]) {
                    if (_pArrayData.count > 0) {
                        [self.pDelegate selShowUserInfo:[_pArrayData firstObject]];
                    }
                }

                [self selAddBottomItem];
            } completion:^(BOOL finished) {
                panView.pEm_Movie_Way = em_no;
                [panView removeGestureRecognizer:pan];
                [panView removeFromSuperview];
                panView = nil;
            }];
        } else {
            [UIView animateWithDuration:0.5 animations:^{
                [pan.view setFrame:DEFAULT_RECT];
            } completion:^(BOOL finished) {
                panView.pEm_Movie_Way = em_no;
            }];
        }
    }
}
- (CGPoint)selRight:(CGPoint)centerPoint
{
    CGFloat dis_x = [UIScreen mainScreen].bounds.size.width + ([UIScreen mainScreen].bounds.size.width - DEFAULT_LEFT_DIS * 2) / 2 - centerPoint.x;
    CGFloat dis_y = 0;
    
    if (centerPoint.y > ([UIScreen mainScreen].bounds.size.width - DEFAULT_LEFT_DIS * 2) / 2 + DEFAULT_TOP) {
        dis_y = [UIScreen mainScreen].bounds.size.height + ([UIScreen mainScreen].bounds.size.width - DEFAULT_LEFT_DIS * 2) / 2 - centerPoint.y;
    } else {
        dis_y = centerPoint.y + ([UIScreen mainScreen].bounds.size.width - DEFAULT_LEFT_DIS * 2) / 2;
    }
    
    if (dis_x > dis_y) {
        if (centerPoint.y > ([UIScreen mainScreen].bounds.size.width - DEFAULT_LEFT_DIS * 2) / 2 + DEFAULT_TOP) {// 底部
            return CGPointMake((centerPoint.x * dis_y) / centerPoint.y, [UIScreen mainScreen].bounds.size.height + ([UIScreen mainScreen].bounds.size.width - DEFAULT_LEFT_DIS * 2) / 2);
        } else { //顶部
            return CGPointMake((centerPoint.x * dis_y) / centerPoint.y, - ([UIScreen mainScreen].bounds.size.width - DEFAULT_LEFT_DIS * 2) / 2);
        }
    } else if(dis_x < dis_y){
        if (centerPoint.y > ([UIScreen mainScreen].bounds.size.width - DEFAULT_LEFT_DIS * 2) / 2 + DEFAULT_TOP) {// 底部
            return CGPointMake([UIScreen mainScreen].bounds.size.width + ([UIScreen mainScreen].bounds.size.width - DEFAULT_LEFT_DIS * 2) / 2, ((centerPoint.y - ([UIScreen mainScreen].bounds.size.width - DEFAULT_LEFT_DIS * 2) / 2 - DEFAULT_TOP) * dis_x) / centerPoint.x + [UIScreen mainScreen].bounds.size.width - DEFAULT_LEFT_DIS * 2 + DEFAULT_TOP);
        } else { //顶部
            return CGPointMake([UIScreen mainScreen].bounds.size.width + ([UIScreen mainScreen].bounds.size.width - DEFAULT_LEFT_DIS * 2) / 2, centerPoint.y);
        }
    } else {
        return CGPointMake([UIScreen mainScreen].bounds.size.width + ([UIScreen mainScreen].bounds.size.width - DEFAULT_LEFT_DIS * 2) / 2, ([UIScreen mainScreen].bounds.size.width - DEFAULT_LEFT_DIS * 2) / 2 + DEFAULT_TOP);
    }
}

- (CGPoint)selLeft:(CGPoint)centerPoint
{
    CGFloat dis_x = centerPoint.x;
    CGFloat dis_y = 0;
    
    if (centerPoint.y > ([UIScreen mainScreen].bounds.size.width - DEFAULT_LEFT_DIS * 2) / 2 + DEFAULT_TOP) {
        dis_y = [UIScreen mainScreen].bounds.size.height + ([UIScreen mainScreen].bounds.size.width - DEFAULT_LEFT_DIS * 2) / 2 - centerPoint.y;
    } else {
        dis_y = centerPoint.y + ([UIScreen mainScreen].bounds.size.width - DEFAULT_LEFT_DIS * 2) / 2;
    }
    
    CGPoint point = CGPointZero;
    if (dis_x > dis_y) {
        if (centerPoint.y > ([UIScreen mainScreen].bounds.size.width - DEFAULT_LEFT_DIS * 2) / 2 + DEFAULT_TOP) {// 底部
            point = CGPointMake((centerPoint.x * dis_y) / centerPoint.y, [UIScreen mainScreen].bounds.size.height + ([UIScreen mainScreen].bounds.size.width - DEFAULT_LEFT_DIS * 2) / 2);
        } else { //顶部
            point = CGPointMake((centerPoint.x * dis_y) / centerPoint.y, - ([UIScreen mainScreen].bounds.size.width - DEFAULT_LEFT_DIS * 2) / 2);
        }
    } else if(dis_x < dis_y){
        if (centerPoint.y > ([UIScreen mainScreen].bounds.size.width - DEFAULT_LEFT_DIS * 2) / 2 + DEFAULT_TOP) {// 底部
            point = CGPointMake(-([UIScreen mainScreen].bounds.size.width - DEFAULT_LEFT_DIS * 2) / 2, (centerPoint.y * dis_x) / centerPoint.x + ([UIScreen mainScreen].bounds.size.width - DEFAULT_LEFT_DIS * 2) / 2 + DEFAULT_TOP);
        } else { //顶部
            point = CGPointMake(-([UIScreen mainScreen].bounds.size.width - DEFAULT_LEFT_DIS * 2) / 2, centerPoint.y);
        }
    } else {
        point = CGPointMake(-([UIScreen mainScreen].bounds.size.width - DEFAULT_LEFT_DIS * 2) / 2, ([UIScreen mainScreen].bounds.size.width - DEFAULT_LEFT_DIS * 2) / 2 + DEFAULT_TOP);
    }
    
    return point;
}

- (void)selSelectMoveWay:(EM_Move_Way)em_movie_way
{
    switch (em_movie_way) {
        case em_right:
        {
            [UIView animateWithDuration:0.5 animations:^{
                _pbtn4.pEm_Movie_Way = em_right;
                [_pbtn4 setCenter:CGPointMake([UIScreen mainScreen].bounds.size.width * 3 / 2, [UIScreen mainScreen].bounds.size.width / 2 + DEFAULT_TOP)];
                [_pbtn1 setFrame:CGRectMake(DEFAULT_RECT.origin.x + 10, DEFAULT_RECT.origin.y + 40, [UIScreen mainScreen].bounds.size.width - (DEFAULT_LEFT_DIS + 10) * 2, [UIScreen mainScreen].bounds.size.height - 220 - 20)];
                [_pbtn2 setFrame:CGRectMake(DEFAULT_RECT.origin.x + 5, DEFAULT_RECT.origin.y + 20, [UIScreen mainScreen].bounds.size.width - (DEFAULT_LEFT_DIS + 5) * 2, [UIScreen mainScreen].bounds.size.height - 220 - 10)];
                [_pbtn3 setFrame:DEFAULT_RECT];
                
                _pbtn4 = _pbtn3;
                _pbtn3 = _pbtn2;
                _pbtn2 = _pbtn1;
                [_pbtn4 setUserInteractionEnabled:YES];
                
                _pbtn1 = nil;
                [self requestUserLike:[_pArrayData firstObject]];
                
                
                if (_pArrayData.count > 0) {
                 [_pArrayData removeObjectAtIndex:0];
                }
                if ([self.pDelegate respondsToSelector:@selector(selShowUserInfo:)]) {
                    if (_pArrayData.count > 0) {
                        [self.pDelegate selShowUserInfo:[_pArrayData firstObject]];
                    }
                }
                [self selAddBottomItem];
            } completion:^(BOOL finished) {

            }];
        }
            break;
            
        case em_left:
        {
            [UIView animateWithDuration:0.5 animations:^{
                _pbtn4.pEm_Movie_Way = em_left;
                [_pbtn4 setCenter:CGPointMake(-[UIScreen mainScreen].bounds.size.width / 2, [UIScreen mainScreen].bounds.size.width / 2 + DEFAULT_TOP)];
                [_pbtn1 setFrame:CGRectMake(DEFAULT_RECT.origin.x + 10, DEFAULT_RECT.origin.y + 40, [UIScreen mainScreen].bounds.size.width - (DEFAULT_LEFT_DIS + 10) * 2, [UIScreen mainScreen].bounds.size.height - 220 - 20)];
                [_pbtn2 setFrame:CGRectMake(DEFAULT_RECT.origin.x + 5, DEFAULT_RECT.origin.y + 20, [UIScreen mainScreen].bounds.size.width - (DEFAULT_LEFT_DIS + 5) * 2, [UIScreen mainScreen].bounds.size.height - 220 - 10)];
                [_pbtn3 setFrame:DEFAULT_RECT];
                
                _pbtn4 = _pbtn3;
                _pbtn3 = _pbtn2;
                _pbtn2 = _pbtn1;
                [_pbtn4 setUserInteractionEnabled:YES];
                _pbtn1 = nil;  
                if (_pArrayData.count > 0) {
                    [_pArrayData removeObjectAtIndex:0];
                }

                if ([self.pDelegate respondsToSelector:@selector(selShowUserInfo:)]) {
                    if (_pArrayData.count > 0) {
                        [self.pDelegate selShowUserInfo:[_pArrayData firstObject]];
                    }
                }

                [self selAddBottomItem];
            } completion:^(BOOL finished) {

            }];
        }
            break;
            
        case em_no:
            break;
            
        default:
            break;
    }
}

- (void)selRloadUserList
{
    for (UIView *item in self.subviews) {
        if (item == btnDisLike || item == btnLike || item == btnRefresh) {
        } else {
            [item removeFromSuperview];
        }
    }
    _pbtn4 = nil;
    _pbtn3 = nil;
    _pbtn2 = nil;
    _pbtn1 = nil;
    [_pArrayData removeAllObjects];
}

- (void)gesTapUserAction:(UITapGestureRecognizer *)tapgestureRecognizer
{
    UIView *view = tapgestureRecognizer.view;
    NSString *strUid = [view accessibilityIdentifier];
    XYuser *selectUser = nil;
    for (XYuser *item in _pArrayData) {
        if ([item.uid isEqualToString:strUid]) {
            selectUser = item;
            break;
        }
    }
    
    if (selectUser && [self.pDelegate respondsToSelector:@selector(selSelectUser:)]) {
        [self.pDelegate selSelectUser:selectUser];
    }
}

- (void)requestUserLike:(XYuser *)user {
    User *my = [User defaultUser];
    if ([my.zambia intValue] > 0)
    {
        if (!user) {
            return;
        }
        
        [TDNetwork requestCollection:MY_COLLECTION_List toUid:[user.uid integerValue] complete:^(BOOL succeed, NSString *ret, NSDictionary *dictionary) {
            if (succeed) {
                int intCode = [[dictionary objectForKey:@"ret"] intValue];
                my.zambia = [NSString stringWithFormat:@"%d", [my.zambia intValue] - 1];
                if (intCode == 1) {
                    [[NSNotificationCenter defaultCenter] postNotificationName:NOTI_ADD_ATTENTION object:nil];
                }
            } else {
                [SVProgressHUD showInfoWithStatus:@"喜欢次数已用完,喜欢失败"];
            }
        }];
    } else {
    }
}

@end
